package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupHourlyDispensingMapper;
import com.yunhai.device.service.OrrOutcupHourlyDispensingService;
import com.yunhai.model.entity.orr.OrrOutcupHourlyDispensingEntity;
import com.yunhai.model.vo.orr.OrrOutcupHourlyDispensingQuery;
import com.yunhai.model.vo.orr.OrrOutcupHourlyDispensingVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupHourlyDispensingServiceImpl implements OrrOutcupHourlyDispensingService {

    @Resource
    private OrrOutcupHourlyDispensingMapper orrOutcupHourlyDispensingMapper;

    /**
     * 获取 OrrOutcupHourlyDispensing 分页列表
     */
    @Transactional
    public IPage getOrrOutcupHourlyDispensingPagination(PaginationVo paginationVo, OrrOutcupHourlyDispensingQuery orrOutcupHourlyDispensingQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupHourlyDispensingEntity> lqs = new LambdaQueryWrapper();
        orrOutcupHourlyDispensingMapper.selectPage(page, lqs);

        List<OrrOutcupHourlyDispensingEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupHourlyDispensing 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupHourlyDispensingEntity> getOrrOutcupHourlyDispensingAllList( OrrOutcupHourlyDispensingQuery orrOutcupHourlyDispensingQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupHourlyDispensingEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupHourlyDispensingEntity> list = orrOutcupHourlyDispensingMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupHourlyDispensing 详情
     */
    @Transactional
    public OrrOutcupHourlyDispensingEntity getOrrOutcupHourlyDispensingDetail( Long id) throws Exception {

        OrrOutcupHourlyDispensingEntity orrOutcupHourlyDispensingEntity = orrOutcupHourlyDispensingMapper.selectById(id);
        return orrOutcupHourlyDispensingEntity;
    }


    /**
     * 新增 OrrOutcupHourlyDispensing
     * */
    @Transactional
    public void addOrrOutcupHourlyDispensing(OrrOutcupHourlyDispensingVo orrOutcupHourlyDispensingVo) throws Exception {

        OrrOutcupHourlyDispensingEntity orrOutcupHourlyDispensingEntity = new OrrOutcupHourlyDispensingEntity();
        ReflectionCopy.copyProperties( orrOutcupHourlyDispensingEntity, orrOutcupHourlyDispensingVo );
        orrOutcupHourlyDispensingMapper.insert(orrOutcupHourlyDispensingEntity);
        return;
    }


    /**
     * 更新 OrrOutcupHourlyDispensing
     * */
    @Transactional
    public void updateOrrOutcupHourlyDispensing( OrrOutcupHourlyDispensingVo orrOutcupHourlyDispensingVo) throws Exception {

        if( orrOutcupHourlyDispensingVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupHourlyDispensingEntity orrOutcupHourlyDispensingEntity = new OrrOutcupHourlyDispensingEntity();
        ReflectionCopy.copyProperties( orrOutcupHourlyDispensingEntity, orrOutcupHourlyDispensingVo );
        orrOutcupHourlyDispensingMapper.updateById(orrOutcupHourlyDispensingEntity);
        return;
    }

    /**
     * 删除 OrrOutcupHourlyDispensing
     * */
    @Transactional
    public void batchRemoveOrrOutcupHourlyDispensing( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupHourlyDispensingMapper.deleteBatchIds(ids);
    }

}